Pattern Matching for Literals and Classes#2
Conversation
Derppening
left a comment
There was a problem hiding this comment.
I think this forms a pretty solid foundation for pattern matching. Please address the comments I left below.
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
| :wat | ||
| class Foo(val x) | ||
| if Foo(42) is Foo(a) then a else 1 |
There was a problem hiding this comment.
This example is good. Could you add one more example with multiple match arms, and add the :wat flag to that instead? I think the case of multiple match arms is more interesting, and it has a similar structure to the one-arm case.
It would be nice to also have examples where the scrutinee does not match any arms and fails as a result - Please also add the :re flag to those test cases to indicate that they result in runtime errors.
There was a problem hiding this comment.
I added more test cases but will need to add more. For example, pat mat inside function or something similar.
hkmc2/shared/src/main/scala/hkmc2/codegen/wasm/text/WatBuilder.scala
Outdated
Show resolved
Hide resolved
|
The CI fails. You forgot to run the tests. Also, please remember to address all PR comments (and pls read this: https://github.com/hkust-taco/mlscript/blob/mlscript/CONTRIBUTING.md). |
LPTK
left a comment
There was a problem hiding this comment.
Nice, it looks reasonable to me!
|
This PR no longer intend to implement tuple literal matchig, right? |
We will implement pattern matching for tuples after we implement arrays, so yes tuples and pat mat for them will be in separate PR. |
|
Please merge with the main branch, fixing the git conflicts. |
This PR is not dependent on #1 . This branch was created from an existing branch hkmc2 and intends to merge only Pattern Matching features.